package com.zyy.other.locator;

/**
 * @Description: 类描述
 * @Author: zyy
 * @Date: 2023/08/12 10:43
 */
public class ServiceLocator {
    private static Cache cache;

    static {
        cache = new Cache();
    }

    //先从缓存中取，取不到再创建，然后放到缓存中
    public Service getService(String serviceName) {
        Service service = cache.getService(serviceName);
        if (service != null) {
            return service;
        }
        InitialContext initialContext = new InitialContext();
        service = initialContext.createService(serviceName);
        cache.addService(service);
        return service;
    }
}
